﻿using System;
using System.Text;
using System.Security.Cryptography;

namespace ShopMall.Common
{
    /// <summary>
    /// MD5加密
    /// </summary>
    public sealed class DesMD5
    {
        /// <summary>
        /// MD5 16位加密 加密后密码为大写
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static string Encrypt_16(string str)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)), 4, 8);
            t2 = t2.Replace("-", "");
            return t2;
        }

        /// <summary>
        /// MD5　32位加密
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static string Encrypt_32(string str)
        {
            if (string.IsNullOrEmpty(str)) return null;
            MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
            return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", "");
        }

    }
}
